SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<victor Regalado>
-- Create date: <04/15/2010>
-- Description:	<update the employee record that has employee.employee_parking_space=null and 
--			     assign the highest parking space + 1 to it.>
-- =============================================
CREATE TRIGGER assing_parking_space 
	ON employee AFTER INSERT 
	AS 
		BEGIN 
			SET NOCOUNT ON;
			DECLARE @newVal int
			SELECT @newVal=((SELECT MAX(emp_parking_space) FROM employee)+1 )
			UPDATE employee SET emp_parking_space=@newVal WHERE emp_parking_space IS NULL;
		END
GO
